package baseFx.common.concurrent;

public class Counter {
    private final Object sync = new Object();
    private int count;

    public Counter() {

    }

    public Counter(int num) {
        count = num;
    }

    public int get() {
        synchronized (sync) {
            return count;
        }
    }

    public int add(int num) {
        synchronized (sync) {
            count += num;
            return count;
        }
    }

    @Override
    public String toString() {
        return String.valueOf(count);
    }
}
